package bma.shop.test.support;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;

import bma.shop.domain.Order;
import bma.shop.domain.Product;

public class HibernateDbSupport implements DbSupport, InitializingBean {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	private HibernateTemplate hbmTpl;
	
	public void afterPropertiesSet() throws Exception {
		hbmTpl = new HibernateTemplate(sessionFactory);
	}

	public void cleanUpAllProducts() {
		List<Product> all = hbmTpl.loadAll(Product.class);
		hbmTpl.deleteAll(all);
	}

	public void cleanUpAllOrders() {
		List<Order> all = hbmTpl.loadAll(Order.class);
		hbmTpl.deleteAll(all);
	}

}
